﻿using System.ServiceModel.Syndication;

namespace Jacobi.Seesmic.FeedReader.Model.Extensions
{
    /// <summary>
    /// Reads the 'çreator' tag from the 'http://purl.org/dc/elements/1.1/' extension.
    /// </summary>
    internal sealed class Purl11Creator
    {
        private static string Namepsace = "http://purl.org/dc/elements/1.1/";
        private static string Name = "creator";

        private Purl11Creator(string creator)
        {
            Creator = creator;
        }

        /// <summary>
        /// Gets the creator value.
        /// </summary>
        public string Creator { get; private set; }

        /// <summary>
        /// Factory method to create a new instance if the extension is present.
        /// </summary>
        /// <param name="extensions">The element extension from the feed item. Must not be null.</param>
        /// <returns>Returns null if the extension is not present.</returns>
        public static Purl11Creator Create(SyndicationElementExtensionCollection extensions)
        {
            foreach (var creator in extensions.ReadElementExtensions<string>(Name, Namepsace))
            {
                return new Purl11Creator(creator);
            }

            return null;
        }
    }
}